package com.hdy.redislikerankinglist.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;

import java.io.Serializable;

@Configuration
@RequiredArgsConstructor
public class RankingListConfig {
    private final APIInfo apiInfo;

    @Bean
    public OpenAPI API(){
        return new OpenAPI()
                .info(new Info()
                        .title(apiInfo.getTitle())
                        .version(apiInfo.getVersion())
                        .description(apiInfo.getDescription()));
    }
    @Bean
    public GroupedOpenApi PublicApi(){
    return GroupedOpenApi.builder()
            .group("public")
            .pathsToMatch("/**")
            .packagesToScan("com.hdy.redislikerankinglist")
            .build();
}

    /*@Bean
    public RedisTemplate<String, Serializable> redisTemplate(RedisConnectionFactory connectionFactory) {
        RedisTemplate<String, Serializable> redisTemplate = new RedisTemplate<>();
        redisTemplate.setKeySerializer(new GenericJackson2JsonRedisSerializer());
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        redisTemplate.setConnectionFactory(connectionFactory);
        return redisTemplate;
    }*/
    @Bean

    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {

        RedisTemplate<String, Object> template = new RedisTemplate<>();

        template.setConnectionFactory(factory);

        template.afterPropertiesSet();

        return template;

    }
}
